import { formatDate } from '@/utils/util'
import Area from '@/components/_util/Area'
import { postAction } from '@/api/manage'

const onlUtil = {
  data(){
    return {
      mixin_pca:'',
      flowCodePre: 'onl_'
    }
  },
  created(){
    this.mixin_pca = new Area()
  },
  methods:{
    simpleDateFormat(millisecond, format){
      return formatDate(millisecond, format)
    },
    getPcaText(code){
      return this.mixin_pca.getText(code);
    },
    getPcaCode(text){
      return this.mixin_pca.getCode(text)
    },
    startProcess: function(record){
      const that = this;
      that.$confirm({
        title:"提示",
        content:"确认提交流程吗?",
        onOk: function(){
          that.doStartProcess(record).then((res)=>{
            that.loadData();
            that.onClearSelected();
          })
        }
      });
    },
    doStartProcess(record){
      const that = this;
      const param = {
        flowCode:that.flowCodePre+that.currentTableName,
        id:record.id,
        formUrl:"modules/bpm/task/form/OnlineFormDetail",
        formUrlMobile:"check/onlineForm/detail"
      }
      return new Promise(resolve => {
        postAction(that.url.startProcess, param).then((res)=>{
          if(res.success){
            that.$message.success(res.message);
            resolve(res);
          }else{
            that.$message.warning(res.message);
          }
        });
      })

    }

  }
}

export  { onlUtil }